<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');
if ( $_SESSION['adminlevel']>1  &&   $_SESSION['is_wage']=='0' && $_SESSION['check_wage']=='0'   ){
	echo "你没有权限";
	exit();
}

require_once "function.php";
//初始化参数

$action  = isset($action)  ? $action  : '';
$repairid = isset($repairid) ? $repairid : ''; //任务类型
$manageid = isset($manageid) ? $manageid : ''; //执行人员
$beginTime = isset($beginTime) ? $beginTime : '';
$endTime = isset($endTime) ? $endTime : '';


?>

<div class="toolbarTab">


	<div class="row tool2">
		<div class="col-md-4">
			<div  class="tool1"><span class="btn btn-success" onclick="getFangAll()"><span class="icon-list-alt icon-white"></span> 全部工资</span></div>
			<div class="tool1"><span class="btn btn-danger" onclick="add_order()"><span class="icon-list-alt icon-white"></span> 创建工资</span></div>
		</div>

		<div class="col-md-4">
			<div class="s-label"><span class="	glyphicon glyphicon-ok-sign"></span> 员工：</div>
			<select  class="form-control w200" name="manageid" id="manageid" onchange="getWageSearch()">
				<option value="-1">所有</option>
				<?php
				$dosql->Execute("SELECT * FROM  `#@__user`  WHERE   level<=4  order by id desc",10);
				while($row = $dosql->GetArray(10))
				{
					if($manageid == $row['id'])
						$selected = 'selected="selected"';
					else
						$selected = '';
					echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['school']."-".$row['truename'].'</option>';
				}

				?>
			</select>
		</div>
		<div class="col-md-4">
			<div class="input-group" style=" float:left;width: 240px; margin-left: -5px;">
				<input class="form-control date-picker" id="dateTimeRange" value="<?php echo $beginTime?>至<?php echo $endTime?>" type="text">
				<span class="input-group-addon"> <i class="glyphicon glyphicon-calendar bigger-110"></i> </span>
				<input name="beginTime" id="beginTime" value="<?php echo $beginTime?>" type="hidden">
				<input name="endTime" id="endTime" value="<?php echo $endTime?>"  type="hidden">
			</div>
			<a href="javascript:;" onclick="begin_end_time_clear();"  style="float:left; margin-left:20px; height:34px; line-height:34px;">清除</a> </div>


		</div>

	</div>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="ajaxlist" class="dataTable table table-striped table-bordered">
	<tr height="50" align="left" class="head">
		<td width="3%">ID</td>
		<td width="10%">工资月份</td>
		<td width="10%">姓名</td>
		<td width="10%">职务</td>
		<td width="15%">创建时间</td>
		<td width="10%">操作</td>
		<td width="10%">审核</td>
	</tr>
	<?php
	//检查全局分页数
	if(empty($cfg_pagenum))  $cfg_pagenum = 50;
	//设置sql
	$sql_order = "SELECT f.* ,u.truename as truename,u.zhiwu as zhiwuid,u.id as newuid ,u.level FROM `#@__wage` as f
	left join `#@__user`   as u on u.id=f.uid
	left join `#@__cascadedata` as z on z.datavalue=u.zhiwu
	WHERE f.is_delete='0' AND z.datagroup='zhiwu'  ";
	if(!empty($manageid)) $sql_order .= " AND f.uid='$manageid'  ";
	if(!empty($is_active)) {
		if($is_active==1){
			$sql_order .= " AND o.level<5  ";
		}
		if($is_active==0){
			$sql_order .= " AND o.level>4 ";
		}
	} 
	if(!empty($beginTime)  && !empty($endTime) ) {
		$starttime = strtotime($beginTime." 00:00");

			$endtime = strtotime($endTime)+86400; //加一天
			$sql_order .= " AND f.creat_time > ". $starttime ." AND f.creat_time < ".$endtime;
		}




		$dopage->GetPage($sql_order,15);
		while($row = $dosql->GetArray())
		{


			
			$zhiwuname=cascadedata('zhiwu',$row['zhiwuid']);
			$uname=$row['truename'];

			if($row['level']==6){
				$uname=$row['truename']."【离职】";

			}
		//获取审核状态
			switch($row['checkinfo'])
			{
				case '1':
				$checkinfo = '已审';
				break;
				case '0':
				$checkinfo = '未审';
				break;
				default:
				$checkinfo = '没有获取到参数';
			}




			//审核权限
			if($cfg_adminlevel != 1 ){
				if($_SESSION['is_wage']=='1')
				{
					if($row['checkinfo']=='0'){
						$updateStr = '<a href="javascript:;" onclick="updateWage('.$row['id'].')">修改</a>';
					$delStr = '<a href="javascript:;" id="m_'.$row['id'].'" data-index="'.$uname.date("Y-m",$row['wage_month']).'"  onclick="delWage('.$row['id'].')">删除</a>';
					}else{
						$updateStr="";
						$delStr ="";
					}
					
				}else{
					$updateStr="";
					$delStr ="";
				}

			}else{
				$updateStr = '<a href="javascript:;" onclick="updateWage('.$row['id'].')">修改</a>';
				$delStr = '<a href="javascript:;" id="m_'.$row['id'].'" data-index="'.$uname.date("Y-m",$row['wage_month']).'"  onclick="delWage('.$row['id'].')">删除</a>';
			}





			//审核权限
			if($cfg_adminlevel != 1 ){
				if($_SESSION['check_wage']=='1')
				{
					$checkStr = '<a href="javascript:;" title="点击进行审核与未审操作" onclick="CheckWage('.$row['id'].',\''.$row['checkinfo'].'\')">'.$checkinfo.'</a>';
				}else{
					$checkStr = "";
				}

			}else{
				$checkStr = '<a href="javascript:;" title="点击进行审核与未审操作" onclick="CheckWage('.$row['id'].',\''.$row['checkinfo'].'\')">'.$checkinfo.'</a>';
			}


			?>
			<tr align="left">
				<td><?php echo $row['id']; ?></td>
				<td>
					<?php 
					
						echo '<a href="javascript:;" onclick="show_wage('.$row['id'].')">
						'.date("Y-m",$row['wage_month']).'</a>';
					?>
				</td>
				<td><?php echo $uname ; ?></td>
				<td><?php echo $zhiwuname;?></td>
				<td><?php echo date("Y-m-d H:i:s",$row['creat_time']);?></td>
				<td><?php echo $updateStr; ?></span>  <span class="nb"><?php echo $delStr; ?></span></td>
				<td><span id="check<?php echo $row['id']; ?>"><?php echo $checkStr; ?></span> <span></td>
				</tr>
				<?php

			}

			?>

		</table>
		<?php



//判断无记录样式

		if($dosql->GetTotalRow() == 0)
		{
			echo '<div class="dataEmpty">暂时没有相关的记录</div>';
		}?>
		<div class="page"> <?php echo $dopage->AjaxWagePage(); ?> </div>
		<?php

		//审核销售

		if($cfg_adminlevel == 1)

		{



			?>
			<?php

		}

//判断是否启用快捷工具栏

		if($cfg_quicktool == 'Y'  && $cfg_adminlevel == 1)

		{

			?>
			<div class="quickToolbar">
				<div class="qiuckWarp">
					<div class="quickArea"><?php echo $dopage->AjaxPageSmall(); ?> </div>
					<div class="quickAreaBg"></div>
				</div>
			</div>
			<?php

		}



		?>
		<script type="text/javascript">
			$(function() {
				$('#dateTimeRange').daterangepicker({
					applyClass : 'btn-sm btn-success',
					cancelClass : 'btn-sm btn-default',
					locale: {
						applyLabel: '确认',
						cancelLabel: '取消',
						fromLabel : '起始时间',
						toLabel : '结束时间',
						customRangeLabel : '自定义',
						firstDay : 1
					},
					ranges : {
			//'最近1小时': [moment().subtract('hours',1), moment()],
			'今日': [moment().startOf('day'), moment()],
			'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
			'最近7日': [moment().subtract('days', 6), moment()],
			'最近30日': [moment().subtract('days', 29), moment()],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")]
		},
		opens : 'right',	// 日期选择框的弹出位置
		separator : ' 至 ',
		showWeekNumbers : true,		// 是否显示第几周


		//timePicker: true,
		//timePickerIncrement : 10,	// 时间的增量，单位为分钟
		//timePicker12Hour : false,	// 是否使用12小时制来显示时间


		maxDate :<?php echo date("Y-m-d",time())?>,			// 最大时间
		format: 'YYYY-MM-DD'

	}, function(start, end, label) { // 格式化日期显示框
		$('#beginTime').val(start.format('YYYY-MM-DD'));
		$('#endTime').val(end.format('YYYY-MM-DD'));
		getWageSearch();
		
	})
				.next().on('click', function(){
					$(this).prev().focus();
				});
			});

/**
 * 清除时间
 */
 function begin_end_time_clear() {
 	$('#dateTimeRange').val('');
 	$('#beginTime').val('');
 	$('#endTime').val('');
 }



 function delM(id){

 	var id_name=$("#m_"+id).data("index");
 	var del_str="您确定要删除    "+id_name+"   吗, 确认删除?";
 	layer.confirm(del_str, function() {
		   //操作 
		   $.ajax({
		   	type: 'POST',
		   	url: "op.php",
		   	data: {id:id,op:'delM'},
		   	dataType: 'JSON',
		   	success:function(result){
		   		console.log(result);
		   		if(result.errno==0){
		   			console.log(result.msg);
		   			if(result.msg==="ok"){
		   				layer.msg('删除成功');
		   				window.location.reload();
		   			}else{
		   				layer.msg(result.err_msg);
		   			}
		   		}
		   	}
		   });
		}, function() {
          //取消操作
      });

 }


</script>
<style>
	.nav-tabs>li.active>a{
		color: #fff !important;
		background-color: #337ab7 !important;
	}
</style>
<script>
	$('#myTabs a').click(function (e) {
		e.preventDefault()
		$(this).tab('show')
	})
</script>